/**
 * @fileOverview
 * WashizuMahjong.
 * http://code.google.com/p/washizu-mahjong/
 */
/**
 * Sending the detail of an action, such as kong, chow... etc.
 * @see Player#AI
 * @see Player#
 * @namespace
 */
var DataTransfer = new function(){
	/**
	 * @type Worker|WebSocket
	 */
	var _interface = {
		postMessage: function(){},
		send: function(){},
		addEventListener: function(){}
	};
	/**
	 * @see DataTransfer-reciveMessage
	 */
	function defaultMessageHandler(_message){
		
	}
	this.__defineSetter__("interface", function(e){
		if(e instanceof Worker || e instanceof WebSocket){
			_interface = e
			this.reciveMessage(defaultMessageHandler)
		}
	});
	
	/**
	 * @param {DataTransfer.data} data The information sent to the interface
	 */
	this.sendMessage =  function(data){
		if(_interface instanceof Worker){
			_interface.postMessage(data);
		}else if(_interface instanceof WebSocket){
			_interface.send(data)
		}
	};
	
	this.reciveMessage = function(handler){
		if(typeof handler != "function"){ 
			return false
		}
		_interface.addEventListener("message", handler);
	};
	/**
	 * @constructor
	 * @param {Player} player
	 * @param {String} action The same as {@link ActionMessage#type}
	 * @param {MahjongTile[]} chowList When the player chow, the player also need to send the detail of their "chow list". See {@link Player#chowList}.
	 */
	this.data = function(player, action, chowList){
		/**
		 * @type Player
		 */
		this.player = player;
		/**
		 * The action of the message. It should be {@link ActionMessage.AbortiveDraw}, {@link ActionMessage.DrawRound}, {@link ActionMessage.Ron}.
		 * @see ActionMessage#type
		 */
		this.action = action;
		/**
		 * @see RoundDetail
		 */
		this.gameDetails = RoundDetail;
		/**
		 * @see Rules
		 */
		this.rule = Rules;
		/**
		 * @type MahjongTile
		 */
		this.dicardTile = players[Game.turn].discardTiles.lastItem();
		/**
		 * @type Number
		 */
		this.numOfPlayers = players.length
	};
}

